/*
 * @(#) $CVSHeader:  $
 *
 * Copyright (C) 2010 by Netcetera AG.
 * All rights reserved.
 *
 * The copyright to the computer program(s) herein is the property of
 * Netcetera AG, Switzerland.  The program(s) may be used and/or copied
 * only with the written permission of Netcetera AG or in accordance
 * with the terms and conditions stipulated in the agreement/contract
 * under which the program(s) have been supplied.
 *
 * @(#) $Id: FeedItemViewActivity.java 39 2010-06-07 21:24:26Z zarko.popovski $
 */
package com.dreamcode.anfeedreader.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.Button;

import com.dreamcode.anfeedreader.collectors.FeedsDAOimpl;
import com.dreamcode.anfeedreader.modelClass.FeedItem;


public class FeedItemWebViewActivity extends Activity {
  
  private Button textViewBtn= null;
  private Button backBtn= null;
  private WebView content = null;
  private FeedsDAOimpl feedsDAO = null;  
  
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    //requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.webfeeditemview);
    initView();
  }

  private void initView() {
    feedsDAO = FeedsDAOimpl.getInstance();
    content = (WebView) findViewById(R.id.item_webview);
    textViewBtn = (Button) findViewById(R.id.textviewbtn);
    backBtn = (Button) findViewById(R.id.backbtn);
    
    Bundle bundle = getIntent().getExtras();
    final int feedItem_id = bundle.getInt("id");
    final FeedItem contentItem = feedsDAO.getFeedItemDetail(FeedItemWebViewActivity.this, feedItem_id);
    content.getSettings().setJavaScriptEnabled(true);
    content.setWebViewClient(new WebViewClient());
    if (contentItem != null) {
      content.loadUrl(contentItem.getLink());
    }
   
    textViewBtn.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View arg0) {
        Intent i = new Intent(FeedItemWebViewActivity.this, FeedItemViewActivity.class);
        i.putExtra("id", feedItem_id);
        startActivity(i);
        finish();
      }
    });
    backBtn.setOnClickListener(new OnClickListener() {
      
      @Override
      public void onClick(View arg0) {
        finish();
      }
    });
    
    
  }

}
